/***********************************************************************************
Name:  PersonAccountHomeLoanDetailController 
Copyright © 2012  Lodha Group
===================================================================================
===================================================================================
Purpose:
-------
Controller for  PersonAccountHomeLoanDetail VF page for customer portal Users
===================================================================================
===================================================================================
History
-------
VERSION    AUTHOR                DATE             DETAIL              
1.0 -   CG Dev Team          14/06/2012      INITIAL DEVELOPMENT
************************************************************************************/
public class  PersonAccountHomeLoanDetailController {

    public PersonAccountHomeLoanDetailController (ApexPages.StandardController controller) {
        Id accountid = ApexPages.currentPage().getParameters().get('id');
        
        person = [select id, Industry__c,Income_Group__c,Profile__c,H_Mobile_No__c from Account where id=:accountid];
        
        System.debug('*********** Account : '+accountid);
        System.debug('*********** Person: '+person);
        
        
        caseDetail();                 
    }
 
          
    public Account person {get;set;}
    public Account c {get;set;}
    public List<Casewrapper> wrapperlist{get;set;}
    
    
    public void caseDetail(){ 
    
        c = [select id,Name,(select Id,AccountId,CaseNumber,Subject,Sub_Type__c,Query_Type__c from Cases) from Account where id=:person.id]; 
        
        System.debug('*********** cases: '+c);
        
        wrapperlist=new List<Casewrapper>();
        
        for(Case  accountcases : c.Cases)
        {
           Casewrapper wrapper=new Casewrapper();
           wrapper.caseaccountId=accountcases.AccountId;
           wrapper.caseId=accountcases.Id;
           wrapper.casenumber=accountcases.CaseNumber;
           wrapper.subject=accountcases.Subject;
           wrapper.querytype=accountcases.Query_Type__c;
           wrapper.subtype=accountcases.Sub_Type__c;
           wrapperlist.add(wrapper);
        }
    }
    
    public class Casewrapper{
    
        public String caseId{get;set;}
        public String caseaccountId{get;set;}
        public String caseaccountname{get;set;}
        public String casenumber{get;set;}
        public String subject{get;set;}
        public String querytype{get;set;}
        public String subtype{get;set;}
    }
    
    public pageReference save() {
    
        try {
            update(person) ;
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        
        return page.PersonAccountHomeLoanDetail;
        
    }
    
    public pageReference NewCase() {
    
        PageReference pageAccount = new PageReference('/apex/CreateCase?def_account_id='+person.Id);
        pageAccount.setRedirect(true);
        return pageAccount;
    
    }
    
    public pageReference edit() {
    
        PageReference pageAccount = new PageReference('/apex/EditPersonAccountHomeLoanDetail?id='+person.Id);
        pageAccount.setRedirect(true);
        return pageAccount;
    
    }
    
    public pageReference cancel() {
        PageReference pageAccount = new PageReference('/apex/PersonAccountHomeLoanDetail?id='+person.Id);
        pageAccount.setRedirect(true);
        return pageAccount ;
    
    }

/************************************ Test Methods *************************************/   
  
    static testmethod void testPersonAccountHomeLoanDetailController(){
        
        Account a=new Account();
        a.RecordTypeId=[Select id from RecordType where SobjectType='Account' AND Name='Person Account' Limit 1].Id;
        a.FirstName='Test';
        a.LastName='Account';
        a.Industry__c='None';
        a.Income_Group__c='None';
        a.Profile__c='None';
        a.H_Mobile_No__c='2342342';
        insert a;
        
        System.debug('*********** A : '+a);
         
        Case c=new Case();
        c.AccountId=a.ID;        
        insert c; 
        
        System.debug('*********** C : '+c);
        
        PageReference PersonAccountHomeLoanDetail = Page.PersonAccountHomeLoanDetail ;
        PersonAccountHomeLoanDetail.getParameters().put('ID',a.ID); 
        test.setCurrentPage(PersonAccountHomeLoanDetail);
        
        ApexPages.StandardController controller = new ApexPages.StandardController(a);
        PersonAccountHomeLoanDetailController acct=new PersonAccountHomeLoanDetailController(controller);
            acct.edit();
            acct.save();
            acct.cancel();
            acct.NewCase();
        
    
    }
}